﻿using System;
using System.Collections.Generic;
using ProjectBase.Core.PersistenceSupport;
using ProjectBase.Core;

namespace SLSYJ.Core
{
    public class Employee : PersistentObject
    {
        #region Constructors
        
        protected Employee()
        {
            InitMembers();
        }

        public Employee(string Name, string Surname, string DNInumber, string CUILnumber)
        {
            Check.Require(!string.IsNullOrEmpty(Name), "Name must be supplied");
            Check.Require(!string.IsNullOrEmpty(Surname), "Surname must be supplied");
            Check.Require(!string.IsNullOrEmpty(DNInumber), "DNI number must be supplied");
            Check.Require(!string.IsNullOrEmpty(CUILnumber), "CUIL number must be supplied");

            this.Name = Name;
            this.Surname = Surname;
            this.DNInumber = DNInumber;
            this.CUILnumber = CUILnumber;
            InitMembers();
        }

        #endregion

        #region Properties

        [DomainSignature]
        public virtual string Name { get; set; }

        [DomainSignature]
        public virtual string Surname { get; set; }

        public virtual string FileNumber { get; set; }

        [DomainSignature]
        public virtual string DNInumber { get; set; }

        [DomainSignature]
        public virtual string CUILnumber { get; set; }

        public virtual DateTime HiringDate { get; set; }

        public virtual DateTime DateOfBirth { get; set; }

        public virtual decimal Salary { get; set; }

        public virtual decimal RemunerativeSalary { get; set; }

        public virtual decimal NonRemunerativeSalary { 
            get { 
                decimal retval = 0;
                if (this.HasAgreement && Category != null)
                    retval = Category.CategoryEmployee.GetBasicSalary(); 
                return retval;
            } 
        }

        public virtual IList<Year> Years { get; set; }

        public virtual Sector CateorySector { get; set; }

        public virtual Branch SectorBranch { get; set; }

        public virtual EmployeeCategory Category { get; set; }

        public virtual IList<Plus> Extras { get; set; }

        public virtual MaritalStatus MaritalStatus { get; set; }

        public virtual Sex Sex { get; set; }

        public virtual Bank EmployeeBank { get; set; }

        public virtual IList<Parent> Parents { get; set; }

        public virtual bool HasAgreement { get; set; }

        public virtual string CardNumber { get; set; }

        public virtual string Comments { get; set; }

        public virtual string Picture { get; set; }

        #endregion

        #region Private Methods

        private void InitMembers()
        {
            Years = new List<Year>();
            Extras = new List<Plus>();
            Parents = new List<Parent>();
        }

        protected override string GetDomainObjectSignature()
        {
            return Name + "|" + Surname + "|" + DNInumber + "|" + CUILnumber;
        }

        #endregion

        #region Public Methods

        public decimal GetGrossSalary()
        {
            return this.Salary + this.RemunerativeSalary + this.NonRemunerativeSalary;
        }

        public decimal GetNetSalary()
        {
            return this.CalculateNetSalary(this.GetGrossSalary());
        }

        private decimal CalculateNetSalary(decimal GrossSalary)
        {
            throw new System.NotImplementedException();
        }

        #endregion
    }
}
